package org.example.struct.array;

/**
 * @author liyishan
 * @date 2024/1/23 13:51
 * @apiNote
 */

public class Test00459RepeatedSubstringPattern {
    public static void main(String[] args) {
        String s = "abcabcabcabc";
        System.out.println(repeatedSubstringPattern1(s));
    }

    public static boolean repeatedSubstringPattern(String s) {
        return (s + s).indexOf(s, 1) != s.length();
    }

    public static boolean repeatedSubstringPattern1(String s) {
        int n = s.length();
        for (int i = 1; i * 2 <= n; i++) {
            if(n % i == 0){
                boolean match = true;
                for(int j = i; j < n; j++){
                    if(s.charAt(j) != s.charAt(j - i)){
                        match = false;
                        break;
                    }
                }
                if(match){
                    return true;
                }
            }
        }
        return false;
    }
}
